package net.iceflow.dunsel.server.handler;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

public class UpperCaseProtocolHandler extends IoHandlerAdapter {

   /**
    * Handler for when an exception was caught
    * @param session Session instance that represents the individual connection
    * @param cause Exception that was thrown
    */
   @Override
   public void exceptionCaught(IoSession session, Throwable cause) {
      // Close connection when unexpected exception is caught.
      session.close(true);
   }

   /**
    * Handler for when a message is received
    * @param session Session instance that represents the individual connection
    * @param message Text message to modify
    */
   @Override
   public void messageReceived(IoSession session, Object message) {
      // Make the received string upper case
      String str = message.toString().toUpperCase();

      // and write it back.
      session.write(str);
   }
}
